package com.qfedu.firstpage.controller;

import com.qfedu.firstpage.entity.Bbook;
import com.qfedu.firstpage.entity.ResponseData;
import com.qfedu.firstpage.service.BookStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author GHJ
 * @date 2021/3/24 22:41
 */
@Api("Book接口")
@RestController
public class BookStoreController {

    @Autowired
    private BookStoreService bookStoreService;

    @ApiOperation(value = "0连载1完本" , produces = "application/json")
    @GetMapping("/findBookStoreByState")
    public ResponseData findBookStoreByState(@RequestParam("bstate") int bstate) {


        List<Bbook> bookStore = bookStoreService.findBookStoreByState(bstate);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }

    @ApiOperation(value = "各个分类" , produces = "application/json")
    @GetMapping("/findBookStoreByTid")
    public ResponseData findBookStoreByTid(@RequestParam("tid") int tid) {


        List<Bbook> bookStore = bookStoreService.findBookStoreByTid(tid);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }

    @ApiOperation(value = "0为免费1为付费" , produces = "application/json")
    @GetMapping("/findBookStoreByStatus")
    public ResponseData findBookStoreByStatus(@RequestParam("bstatus") int bstatus) {

        List<Bbook> bookStore = bookStoreService.findBookStoreByStatus(bstatus);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }


    @ApiOperation(value = "F为女生类M为男生类" , produces = "application/json")
    @GetMapping("/findBookStoreBySex")
    public ResponseData findBookStoreBySex(@RequestParam("bsex") String bsex) {

        List<Bbook> bookStore = bookStoreService.findBookStoreBySex(bsex);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }

    @ApiOperation(value = "全局搜素" , produces = "application/json")
    @GetMapping("/findBookStoreByName")
    public ResponseData findBookStoreByName(@RequestParam("name") String name) {

        List<Bbook> bookStore = bookStoreService.findBookStoreByName(name);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }

    @ApiOperation(value = "按销量排序展示" , produces = "application/json")
    @GetMapping("/findBookStoreByAmount")
    public ResponseData findBookStoreByAmount() {

        List<Bbook> bookStore = bookStoreService.findBookStoreByAmount();

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }


    @ApiOperation(value = "书城查询" , produces = "application/json")
    @GetMapping("/findBookStore")
    public ResponseData findBookStore(@RequestParam("bsex") String bsex,@RequestParam("bstate") int bstatus,@RequestParam("bstate") int bstate,@RequestParam("tid") int tid) {

        List<Bbook> bookStore = bookStoreService.findBookStore(bsex, bstatus, bstate, tid);

        ResponseData responseData = new ResponseData();

        responseData.setMessage("success");
        responseData.setCode("1");
        responseData.setData(bookStore);

        return responseData;


    }


}
